package com.qf.service.impl;

import com.qf.api.CacheFeign;
import com.qf.constant.CacheConstants;
import com.qf.constant.StrategyConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.FilterChainService;
import com.qf.util.PushMsgUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author WzYu
 * @date 2022-6-11 上午 9:59
 */
@Service("black")
@Slf4j
public class BlackFilterServiceImpl implements FilterChainService {

    @Autowired
    private CacheFeign cacheFeign;
    @Autowired
    private PushMsgUtil pushMsgUtil;
    @Override
    public boolean strategy(StandardSubmit standardSubmit) {
        log.info("[策略模块 - 黑名单策略] 策略开始执行");
        String destMobile = standardSubmit.getDestMobile();
        String i = cacheFeign.get(CacheConstants.CACHE_PREFIX_BLACK + destMobile);
        if (!StringUtils.isEmpty(i)&&"1".equals(i)){
            log.info("[策略模块 - 黑名单策略] 黑名单策略执行失败！！！");
            pushMsgUtil.sendLog(standardSubmit, StrategyConstants.STRATEGY_ERROR_BLACK);

            pushMsgUtil.pushReport(standardSubmit,"手机号是黑名单上的手机号，不可以发送短信");
            return false;
        }
        log.info("[策略模块 - 黑名单策略] 黑名单策略执行成功！！！");
        return true;
    }
}
